Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

Notes/Domino 8 Forum

Notes/Domino 8 Forum

Previous Next
Subject: Java agent parsing XML - read attributes
Feedback Type: Question
Product Area: Designer Client
Technical Area: Application development
Platform: Windows XP client
Release: 8.0
Reproducible: Not applicable

I have an agent in Java that parse XML files in a Body field, creating Notes documents based on the content of the XML file.

I can read the Nodes values, but not the attributes. What code needs to be added to read attributes of a Node? Code below works fine, except reading attr. (As I'm bad at Java I have no idea how to)

example of attribute is currency below:
<Total currency="USD"></Total>


import lotus.domino.*;
import java.util.*;

public class JavaAgent extends AgentBase
{

public void NotesMain()
{

try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// (Your code goes here)
Database db=agentContext.getCurrentDatabase();
//get reference to documents with xml attachments
DocumentCollection collection=agentContext.getUnprocessedDocuments();
Document doc=collection.getFirstDocument();
while(doc!=null)
{
RichTextItem body=(RichTextItem)doc.getFirstItem("Body");
//get reference to xml attachment
Vector objects=body.getEmbeddedObjects();

for (int i = 0; i < objects.size() ; i++)
{
EmbeddedObject emo = (EmbeddedObject)objects.get(i);
if(emo.getType()==EmbeddedObject.EMBED_ATTACHMENT)
{
//parse xml attahcment and create dom Document object
org.w3c.dom.Document document=emo.parseXML(false);
//get reference to root element SalesOrder
org.w3c.dom.Element rootElement=document.getDocumentElement();
//get reference to order child nodes
org.w3c.dom.NodeList orders=rootElement.getElementsByTagName("Order");

for(int j=0; j < orders.getLength(); j++)
{
org.w3c.dom.Node order=orders.item(j);
//create notes order document
Document orderDoc=db.createDocument();
orderDoc.replaceItemValue("Form", "Order");
//get reference to all order details: order id, item and quantity
org.w3c.dom.NodeList orderDetails=order.getChildNodes();

for(int k=0; k < orderDetails.getLength(); k++)
{
//replace field values with order details
org.w3c.dom.Node orderDetail=orderDetails.item(k);
if(orderDetail.getNodeName().equals("Id"))
orderDoc.replaceItemValue("OrderId", orderDetail.getFirstChild().getNodeValue());
else if(orderDetail.getNodeName().equals("Item"))
orderDoc.replaceItemValue("Item", orderDetail.getFirstChild().getNodeValue());
else if(orderDetail.getNodeName().equals("Quantity"))
orderDoc.replaceItemValue("Quantity", orderDetail.getFirstChild().getNodeValue());
}

orderDoc.save(false, false);
}
}
}
doc=collection.getNextDocument(doc);
}

}
catch(Exception e)
{
e.printStackTrace();
}
}
}


Feedback number WEBB84Q9CB created by ~Keiko Destootexettu on 04/21/2010






Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS